package org.manusoft.refill.service;

import java.util.List;
import java.util.Map;

import org.manusoft.refill.dao.DriverDAO;
import org.manusoft.refill.domain.TDriverDetailsRf;
import org.primefaces.model.SortOrder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service("driverService")
public class DriverServiceImpl implements DriverService {

	@Autowired
	private DriverDAO driverDAO;

	@Transactional
	public void createNew(TDriverDetailsRf driverDetailsRf) {
		driverDAO.makePersistent(driverDetailsRf);
	}

	@Transactional(readOnly = true)
	public List<TDriverDetailsRf> findAll() {
		return driverDAO.findAll();
	}

	@Transactional
	public void update(TDriverDetailsRf driverDetailsRf) {
		driverDAO.makePersistent(driverDetailsRf);
	}

	@Transactional
	public void remove(TDriverDetailsRf driverDetailsRf) {
		driverDAO.remove(driverDetailsRf);
	}

	@Transactional(readOnly = true)
	public TDriverDetailsRf findById(Integer id, boolean isLock) {
		return driverDAO.findById(id, isLock);
	}

	@Transactional(readOnly = true)
	public Long getRowCount(Map<String, String> filters) {
		return driverDAO.getRowCount(filters);
	}

	@Transactional(readOnly = true)
	public List<TDriverDetailsRf> loadLazy(int first, int pageSize,
			String sortField, SortOrder sortOrder, Map<String, String> filters) {
		return driverDAO.loadLazy(first, pageSize, sortField,
				sortOrder == SortOrder.ASCENDING ? "asc"
						: sortOrder == SortOrder.DESCENDING ? "desc" : null,
				filters);
	}

	@Override
	@Transactional
	public TDriverDetailsRf createUpdateDriver(TDriverDetailsRf driverDetailsRf) {
		return driverDAO.makePersistent(driverDetailsRf);
	}

	@Override
	public void delete(TDriverDetailsRf driverDetailsRf) {
		driverDAO.remove(driverDetailsRf);
	}

	@Transactional(readOnly = true)
	public List<TDriverDetailsRf> findByDlNoAutoComplete(String regNum) {
		return driverDAO.findByDlNoAutoComplete(regNum);
	}

	@Transactional(readOnly = true)
	public TDriverDetailsRf findByDlNo(String name) {
		return driverDAO.findByDlNo(name);
	}

}